<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Classify;
use App\Cases;
use App\Comments;
use Illuminate\Support\Facades\Input;

class IndexController extends Controller
{
    public function index()
    {
        $cases=Cases::getRecommend();
        return view('pages.index',['cases'=>$cases]);
    }

    public function about(){
        $cases=Cases::getRecommend();
        return view('pages.about',['cases'=>$cases]);
    }

    public function classify($id=0){
       $classifyInfo=Classify::getClassifyInfo($id);
       $classify_name='';
       if($id == 0){
           $classify_name='案例展示';
       }elseif($classifyInfo){
           $classify_name=$classifyInfo->name;
       }else{
           abort(404, '页面未找到！');
       }

       if($id == 0){
           $where="`classify_id` = {$id}";
       }else{
           $where="1 = 1";
       }
       $cases=Cases::pageCase($id,9);
       return view('pages.classify',['classify_name'=>$classify_name,'cases'=>$cases]);
    }

    public function showcase($id){
        $case_info=Cases::getCaseInfo($id);
        if(!$case_info){
            abort(404, '页面未找到！');
        }
        return view('pages.showcase',['case_info'=>$case_info]);
    }

    public function submit_comment(){
        $comment=new Comments();
        $response=array();

        $comment->name=Input::get('name');
        $comment->email=Input::get('email');
        $comment->mobile=Input::get('mobile');
        $comment->content=Input::get('content');
        if($comment->name=='' || $comment->email=='' || $comment->mobile=='' || $comment->content==''){
            $response['status']=0;
            $response['message']='提交失败，信息填写不完整！';
            return response()->json($response);
        }
        if($comment->save()){
            $response['status']=1;
            $response['message']='提交成功,我们将尽快联系你。';
            return response()->json($response);
        }else{
            $response['status']=0;
            $response['message']='提交失败，服务器出错，请稍后重试。';
            return response()->json($response);
        }



    }


}
